
import Head from 'next/head'

<Head>
  <script>
    {
      `(function() {
         var _hmt = _hmt || [];
(function() {
  var hm = document.createElement("script");
  hm.src = "https://hm.baidu.com/hm.js?e60fb290e204e04c5cb6f79b0ac1e697";
  var s = document.getElementsByTagName("script")[0]; 
  s.parentNode.insertBefore(hm, s);
})();
       })();`
    }
  </script>
</Head>

![LangChain](https://pica.zhimg.com/50/v2-56e8bbb52aa271012541c1fe1ceb11a2_r.gif)



OpenWeatherMap
=================

本教程将介绍如何使用OpenWeatherMap组件获取天气信息。

首先，您需要注册OpenWeatherMap API密钥：

1. 前往OpenWeatherMap并注册API密钥 [这里](https://openweathermap.org/api/)
2. 安装pyowm：'pip install pyowm'

然后，我们需要设置一些环境变量：

1. 将您的API KEY保存到OPENWEATHERMAP_API_KEY环境变量中

```python
pip install pyowm

```

```python
import os
os.environ["OPENWEATHERMAP_API_KEY"] = ""

```

```python
from langchain.utilities import OpenWeatherMapAPIWrapper

```

```python
weather = OpenWeatherMapAPIWrapper()

```

```python
weather_data = weather.run("London,GB")

```

```python
print(weather_data)

```

```python
In London,GB, the current weather is as follows:
Detailed status: overcast clouds
Wind speed: 4.63 m/s, direction: 150°
Humidity: 67%
Temperature: 
  - Current: 5.35°C
  - High: 6.26°C
  - Low: 3.49°C
  - Feels like: 1.95°C
Rain: {}
Heat index: None
Cloud cover: 100%

```

